package com.jdrx.sw.sewage.mq;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jdrx.sw.sewage.service.AlarmDataHandleServiceImpl;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
@RocketMQMessageListener(topic = "sewage-device-data-smart", consumerGroup = "sewage-device-data-sewage-group-smart", consumeThreadMax = 1)
public class DataAnalysisListener implements RocketMQListener<String> {

    private static final Logger logger = LoggerFactory.getLogger(DataAnalysisListener.class);
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private AlarmDataHandleServiceImpl alarmDataHandleServiceImpl;

    @Override
    public void onMessage(String message) {
        try {
            logger.debug("收到mq数据" + message);
            logger.info("==================收到mq数据===============");
            Map<String, Object> map = objectMapper.readValue(message, Map.class);
            alarmDataHandleServiceImpl.handleAlarmData(map);
        } catch (Exception e) {
            logger.error("=================数据处理失败==================", e);
        }
    }
}
